package com.myhome.demo;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class ThreadPoolDemo {
    private static Executor executor = Executors.newFixedThreadPool(10);

    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            System.out.print(i + ":");
            executor.execute(new Task());
        }
    }

    static class Task implements Runnable {

        @Override
        public void run() {
            try {
                System.out.println("休息一下...............");
                Thread.sleep(1000l);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程：" + Thread.currentThread().getName());
        }
    }
}
